package com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt;

import android.os.Bundle;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.bean.CardDeskGroupGetGroupBean;
import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @创建者 chenchao.
 * @创建时间 2017/11/9 19:26
 * @描述 ${TODO}
 */

public class DownClassFragment extends CommonBasePagerFragment {

    private String mAuthorizerId;
    private String mUserId;
    private String mLeadFaceUrl;
    private String mLeadName;

    @Override
    public void setTitle() {
        if (peekFragment() instanceof DownClassFragment) {
            mActivity.setTitle(R.string.teamdesk_his_undering);
        }

    }

    @Override
    public void requestDatas() {
        super.requestDatas();
        hideConfirmButton();
        if (getArguments() != null) {
            mUserId = getArguments().getString("userId");
            mLeadFaceUrl = getArguments().getString("leadFaceUrl");
            mLeadName = getArguments().getString("leadName");
        }
        requestHttp();
    }

    private void requestHttp() {
        Map<String, Object> downClassMap = new HashMap<>();
        downClassMap.put("authorizerId", mUserId);
        downClassMap.put("page", 1);
        downClassMap.put("size", 9);
        loadData(CardDeskConstant.GET_DOWN_INFO, downClassMap, 0);
    }

    @Override
    public void onRefreshListener() {
        requestHttp();
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (0 == what) {
            CardDeskGroupGetGroupBean cardDeskGroupGetGroupBean = JSON.parseObject(data, CardDeskGroupGetGroupBean.class);
            int total = cardDeskGroupGetGroupBean.getTotal();
            if (0 == total) {
                mRlEmptyLayout.setVisibility(View.VISIBLE);
                mEmptyText.setText(R.string.teamdesk_no_down_class);
                mStateLayout.showContentView();
//                try {
//                    setData(0, 0, "com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt.DownClassFragmentChild", null, null);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
            } else {
                ArrayList<CardDeskGroupGetGroupBean.ListBean> list = (ArrayList<CardDeskGroupGetGroupBean.ListBean>) cardDeskGroupGetGroupBean.getList();
                Bundle downClassToChildBundle = new Bundle();
                downClassToChildBundle.putString("authorizerId", mUserId);
                downClassToChildBundle.putString("leadFaceUrl", mLeadFaceUrl);
                downClassToChildBundle.putString("leadName", mLeadName);
                try {
                    setData(total, 9, "com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt.DownClassFragmentChild", downClassToChildBundle, list);
                } catch (Exception e) {
                    LogUtils.showLog(e.toString());
                }
            }

        }
    }

    @Override
    public void onLoadError(String errorInfo) {

    }

    @Override
    public void onDownPull() {
//        super.onDownPull();
    }
}
